home *** CD-ROM | disk | FTP | other *** search
/ s-gikan2.maizuru-ct.ac.jp / s-gikan2.maizuru-ct.ac.jp.zip / s-gikan2.maizuru-ct.ac.jp / pub / ncvc352_install.exe / {app} / scripts / transpose_macro_set / transpose_macro(FANUC).pl < prev   
Perl Script  |  2011-03-29  |  42KB  |  1,646 lines

  1. #! /usr/bin/perl
  2.  
  3. #  Version 1.7
  4.  
  5. #  â}âNâìî─é╤Åoé╡û╜ù▀üAâTâuâvâìâOâëâÇî─é╤Åoé╡û╜ù▀é≡è▄é▐NCâfü[â^é≡üAü@  #
  6. #  é╗éΩéτé¬Ä└ìsé│éΩé╜Å≤æ╘é╔Æuè╖é╡é─üAêΩé┬é╠âvâìâOâëâÇé╔é╖éΘâXâNâèâvâg  #
  7. #  é▄é╜üAâ}âNâìò╢é≡ò╜ê╒é╚NCò╢é╔ò╧è╖é╖éΘ                                #
  8.  
  9. ####èeÄφÉ▌ÆΦ############################################################
  10. # â}âNâìâvâìâOâëâÇüAâTâuâvâìâOâëâÇùpé╠âtâHâïâ_é╠âpâXé≡ôoÿ^é╡é─é¡é╛é│éóüB
  11. # âtâHâïâ_û╝é╠ì┼îπé╔\é═é┬é»é╚éóé┼ë║é│éóüB
  12. $macro_folder= 'C:\Program Files\NCVC\macro';
  13.  
  14. # âVâXâeâÇò╧Éöé≡Ägùpé╖éΘÅΩìçé┼üAÅëè·Ælé¬òKùvé╚éαé╠é═Ælé≡ôoÿ^é╡é─é¡é╛é│éóüB
  15. # Åëè·Å≤æ╘é╠GâRü[âhé╠âéü[â_âïÅεò±é¬êßéñÅΩìçéαô»ùlüB
  16. #%system_value= (,);
  17.  
  18. # ôαòöÅêù¥ïyé╤üAò╧è╖æOé╠î┤ò╢é≡âRâüâôâgÅoù═é╖éΘÅΩìçé═1üAé╡é╚éóÅΩìçé═0é≡É▌ÆΦé╡é─é¡é╛é│éóüB
  19. # é╜é╛é╡üAì┼Æßî└é╠ôαòöÅêù¥é═0é≡É▌ÆΦé╡é─éαÅoù═é│éΩé▄é╖üB
  20. $debug_flag= 0;
  21. # âéü[â_âïÅεò±é≡âRâüâôâgÅoù═é╖éΘÅΩìçé═1üAé╡é╚éóÅΩìçé═0é≡É▌ÆΦé╡é─é¡é╛é│éóüB
  22. $modal_flag= 0;
  23.  
  24. # FâRü[âhé┼ÄwÆΦé╖éΘÉöÆlé╠żÉöô_ê╚ë║é¬0é╠é╞é½üA
  25. # Å¼Éöô_é≡Åoù═é╡é╚éóÅΩìçé═0üA
  26. # Å¼Éöô_é≡Åoù═é╖éΘÅΩìçé═1é≡É▌ÆΦé╡é─é¡é╛é│éóüB
  27. $F_flag= 0;
  28.  
  29. # âIâvâVâçâiâïâuâìâbâNâXâLâbâvé≡ùLî°(ON)é╔é╡é╜éóÅΩìçé═1üA
  30. # û│î°(OFF)é╔é╡é╜éóÅΩìçé═0é≡É▌ÆΦé╡é─é¡é╛é│éóüB
  31. $OBS_switch= 0;
  32.  
  33. # M98é╠îJéΦò╘é╡Éöé╠ÄwÆΦò√û@é╔é┬éóé─üA
  34. # M98Pü¢ü¢ü¢ü¢Lü¢ü¢ü¢ü¢é╠Lé┼ÄwÆΦé╖éΘò√Ä«é╠ÅΩìçé═0üA
  35. # M98Pü¢ü¢ü¢ü¢ü¢ü¢ü¢ü¢é╠æO4îàé┼ÄwÆΦé╖éΘò√Ä«é╠ÅΩìçé═1é≡É▌ÆΦé╡é─é¡é╛é│éóüB
  36. $M98_houshiki= 0;
  37. ########################################################################
  38.  
  39. $PI= 3.1415926535897932;
  40. $RAD= 180/$PI;
  41.  
  42. %c= ("A","1","B","2","C","3","D","7","E","8","F","9","H","11","I","4","J","5","K","6","M","13","Q","17","R","18","S","19","T","20","U","21","V","22","W","23","X","24","Y","25","Z","26");
  43.  
  44. %G_group= (00,1,01,1,02,1,03,1,15,17,16,17,17,2,18,2,19,2,20,6,21,6,22,4,23,4,33,1,40,7,41,7,42,7,40.1,19,150,19,41.1,19,151,19,42.1,19,152,19,43,8,44,8,49,8,50,11,51,11,50.1,18,51.1,18,54,14,54.1,14,55,14,56,14,57,14,58,14,59,14,61,15,62,15,63,15,64,15,66,12,67,12,68,16,19,16,73,9,74,9,75,1,76,9,77,1,78,1,79,1,80,9,81,9,82,9,83,9,84,9,85,9,86,9,87,9,88,9,89,9,90,3,91,3,94,5,95,5,96,13,97,13,98,10,99,10,160,20,161,20);
  45.  
  46. %initial_G= (1,00,17,15,2,17,4,22,7,40,19,40.1,8,49,11,50,18,50.1,14,54,15,64,12,67,16,69,9,80,3,90,5,94,13,97,10,98,20,160);
  47.  
  48. %system_value_modal= ("B",4102,"F",4109,"H",4111,"M",4113,"S",4119,"T",4120);
  49.  
  50. $macro_folder= $macro_folder."\\";
  51.  
  52. ($pre_file,$out_file)= ($ARGV[0],$ARGV[1]);
  53. open(IN,$pre_file);
  54. while(<IN>){
  55.     push(@main,$_);
  56. }
  57. close(IN);
  58.  
  59. $pre_folder= $pre_file;
  60. $pre_folder =~ s/\\[^\\]+?$/\\/;
  61.  
  62. opendir(DIR,$pre_folder);
  63. @macro_files2= readdir(DIR);
  64. closedir(DIR);
  65.  
  66. opendir(DIR,$macro_folder);
  67. @macro_files= readdir(DIR);
  68. closedir(DIR);
  69.  
  70. open(OUT,">$out_file");
  71. main();
  72. close(OUT);
  73.  
  74. sub main{
  75.     my ($i,$j);
  76.  
  77.     $macro_level= 0;
  78.     $yobidashi_tajuudo= 0;
  79.     $proto_prog_No= 0;
  80.     $G66_modal_tajuudo= 0;
  81.     $G66_yobidashi_tajuudo= 0;
  82.  
  83.     @initial_G_key= keys(%initial_G);
  84.     @initial_G_key= sort{$a <=> $b} @initial_G_key;
  85.     if($modal_flag == 1){ print OUT '(----GâRü[âhèeâOâïü[âvé╠âéü[â_âïÅëè·ë╗èJÄn----)'."\n"; }
  86.     foreach $key(@initial_G_key){
  87.         modal_shori($key+4000,$initial_G{$key});
  88.     }
  89.     if($modal_flag == 1){ print OUT '(----GâRü[âhèeâOâïü[âvé╠âéü[â_âïÅëè·ë╗ÅIù╣----)'."\n"; }
  90.  
  91.     @system_value_key= keys(%system_value);
  92.     if(@system_value_key != 0){
  93.         @system_value_key= sort{$a <=> $b} @system_value_key;
  94.         if($debug_flag == 1){ print OUT '(---âVâXâeâÇò╧Éöôoÿ^èJÄn---)'."\n"; }
  95.         foreach $key(@system_value_key){
  96.             $value[$key]= $system_value{$key};
  97.             print OUT '(---#'.$key.'= '.$system_value{$key}.'---)'."\n";
  98.         }
  99.         if($debug_flag == 1){ print OUT '(---âVâXâeâÇò╧Éöôoÿ^ÅIù╣---)'."\n"; }
  100.     }
  101.  
  102.  
  103.     for($i=0;$i<=$#main;$i++){
  104.         $_= $main[$i];
  105.         original_print($_);
  106.  
  107.         if(/^\s*\//){
  108.             if($OBS_switch == 1){
  109.                 OBS_skip_print();
  110.                 next;
  111.             }
  112.             else{ $_= $'; }
  113.         }
  114.  
  115.         if(/^\s*(\%)/){ print OUT $1.$'; }
  116.         elsif(/^\s*O([0-9]+)/){
  117.             $proto_prog_No= $1;
  118.             print OUT $_;
  119.             modal_shori(4115,$proto_prog_No);
  120.         }
  121.         else{
  122.             if(/^\s*N0*([0-9]+)/){
  123.                 modal_shori(4114,$1);
  124.                 $_= $';
  125.             }
  126.             if(/\(/){ $_= kakko_print($_); }
  127.             shikaku_kakko_kensa($_);
  128.  
  129.             if(/IF/){ $i= bunki_shori($_,$i,@main); }
  130.             elsif(/GOTO/){ $i= idou_shori($_,@main); }
  131.             elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$proto_prog_No,@main); }
  132.             elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,$proto_prog_No,@main); }
  133.             elsif(/^\s*G65/){
  134.                 $i= macro_G65($_,$i);
  135.                 modal_shori(4115,$proto_prog_No);
  136.             }
  137.             elsif(/^\s*G66/){ $i= macro_G66($_,$i,$proto_prog_No,@main); }
  138.             elsif(/^\s*M98/){
  139.                 $i= sub_M98($_,$i);
  140.                 modal_shori(4115,$proto_prog_No);
  141.             }
  142.             else{
  143.                 $_= main_henkan($_);
  144.                 if(/(M30)/ or /(M0?2)[A-Z\s]/){
  145.                     print OUT $1."\n\%\n";
  146.                     last;
  147.                 }
  148.                 if(/M99/){
  149.                     print OUT;
  150.                     last;
  151.                 }
  152.                 extra_print($_);
  153.             }
  154.  
  155.             if($i eq "M30" or $i eq "M02" or $i eq "M2" or $i eq "M99"){
  156.                 print OUT $i."\n\%\n";
  157.                 last;
  158.             }
  159.         }
  160.     }
  161. }
  162.  
  163. sub hikisuu_watashi{
  164.     ($_)= @_;
  165.     my ($mode_J,$mode_K,$IJK);
  166.     $IJK= 0;
  167.     while(/([ABCDEFIJKHMQRSTUVWXYZ])([0-9\.\-]+)/g){
  168.         ($char,$num)= ($1,$2);
  169.         if($char=~ /[ABCDEFHMQRSTUVWXYZ]/){
  170.             $local_value[$macro_level][$c{$char}]= $num;
  171.             if($debug_flag == 1){ print OUT '(---#'.$c{$char}.'= '.$num.'---)'."\n"; }
  172.         }
  173.         elsif($char =~ /I/){
  174.             $IJK++;
  175.             ($mode_J,$mode_K)= (0,0);
  176.             $local_value[$macro_level][3*$IJK+1]= $num;
  177.             if($debug_flag == 1){ print OUT '(---#'.(3*$IJK+1).'= '.$num.'---)'."\n"; }
  178.         }
  179.         elsif($char =~ /J/){
  180.             if($IJK == 0 or $mode_J == 1 or $mode_K == 1){
  181.                 $IJK++;
  182.                 $mode_K= 0;
  183.             }
  184.             $mode_J= 1;
  185.             $local_value[$macro_level][3*$IJK+2]= $num;
  186.             if($debug_flag == 1){ print OUT '(---#'.(3*$IJK+2).'= '.$num.'---)'."\n"; }
  187.         }
  188.         elsif($char =~ /K/){
  189.             if($IJK == 0 or $mode_K == 1){
  190.                 $IJK++;
  191.             }
  192.             $mode_K= 1;
  193.             $local_value[$macro_level][3*$IJK+3]= $num;
  194.             if($debug_flag == 1){ print OUT '(---#'.(3*$IJK+3).'= '.$num.'---)'."\n"; }
  195.         }
  196.     }
  197. }
  198.  
  199. sub hensuu_haki{
  200.     my $i;
  201.     for($i=1;$i<=33;$i++){
  202.         undef($local_value[$macro_level][$i]);
  203.     }
  204. }
  205.  
  206. sub prog_yomikomi{
  207.     my ($prog_No)= @_;
  208.     my ($prog_file,@prog);
  209.     my ($prog_flag1,$prog_flag2)= (0,0);
  210.     my $i;
  211.  
  212.     for($i=0;$i<=$#main;$i++){
  213.         $_= $main[$i];
  214.         if(/^\s*O0*$prog_No/){ ($prog_flag1,$prog_flag2)= (1,1); }
  215.         elsif(/^\s*O[0-9]+/){ $prog_flag2= 0; }
  216.  
  217.         if($prog_flag2 == 1){ push(@prog,$_); }
  218.     }
  219.  
  220.     if($prog_flag1 == 0){
  221.         for($i=0;$i<=$#present_prog;$i++){
  222.             $_= $present_prog[$i];
  223.             if(/^\s*O0*$prog_No/){ ($prog_flag1,$prog_flag2)= (1,1); }
  224.             elsif(/^\s*O[0-9]+/){ $prog_flag2= 0; }
  225.  
  226.             if($prog_flag2 == 1){ push(@prog,$_); }
  227.         }
  228.     }
  229.  
  230.     if($prog_flag1 == 0){
  231.         foreach(@macro_files2){
  232.             if(/O0*$prog_No[^\d]/ and (/O0*$prog_No\s*\./ or /O0*$prog_No\s*\(.*?\)\s*\./)){
  233.                 $prog_file= $pre_folder.$_;
  234.                 last;
  235.             }
  236.         }
  237.  
  238.         if(! defined($prog_file)){
  239.             foreach(@macro_files){
  240.                 if(/O0*$prog_No[^\d]/ and (/O0*$prog_No\s*\./ or /O0*$prog_No\s*\(.*?\)\s*\./)){
  241.                     $prog_file= $macro_folder.$_;
  242.                     last;
  243.                 }
  244.             }
  245.         }
  246.  
  247.         if(defined($prog_file)){
  248.             undef(@present_prog);
  249.  
  250.             open (IN, $prog_file) or return;
  251.             while(<IN>){
  252.                 push(@present_prog,$_);
  253.             }
  254.             close (IN);
  255.  
  256.             foreach(@present_prog){
  257.                 if(/^\s*O0*([\d]+)/){
  258.                     if($1 == $prog_No){ $prog_flag1= 1; }
  259.                     else{ $prog_flag2= 1; }
  260.                 }
  261.             }
  262.  
  263.             if($prog_flag1 == 1){
  264.                 for($i=0;$i<=$#present_prog;$i++){
  265.                     $_= $present_prog[$i];
  266.                     if(/^\s*O0*$prog_No/){ $prog_flag2= 1; }
  267.                     elsif(/^\s*O[0-9]+/){ $prog_flag2= 0; }
  268.  
  269.                     if($prog_flag2 == 1){ push(@prog,$_); }
  270.                 }
  271.             }
  272.             elsif($prog_flag2 == 0){ @prog= @present_prog; }
  273.         }
  274.     }
  275.  
  276.     return @prog;
  277. }
  278.  
  279. sub macro_G65{
  280.     my ($line,$gyou)= @_;
  281.     my ($i,$j,$k,$macro_No,$kurikaeshi_suu,@macro);
  282.  
  283.     $line= main_henkan($line);
  284.     if($line =~ /P0*([0-9]+)/){
  285.         $macro_No= $1;
  286.         if($line =~ /L([0-9]+)/){ $kurikaeshi_suu= $1; }
  287.         else{ $kurikaeshi_suu= 1; }
  288.  
  289.         @macro= prog_yomikomi($macro_No);
  290.         if(! defined(@macro)){
  291.             print OUT $line;
  292.             print OUT '(---O'.$macro_No.'é¬î⌐é┬é⌐éΦé▄é╣é±---)'."\n";
  293.             return $gyou;
  294.         }
  295.  
  296.         $macro_level++;
  297.         $yobidashi_tajuudo++;
  298.         if($macro_level == 5){
  299.             print OUT '(---â}âNâìæ╜Ådôxé¬î└ôxé≡Æ┤éªé▄é╡é╜---)'."\n";
  300.             close(OUT);
  301.             exit;
  302.         }
  303.         if($yobidashi_tajuudo == 9){
  304.             print OUT '(---î─é╤Åoé╡æ╜Ådôxé¬î└ôxé≡Æ┤éªé▄é╡é╜---)'."\n";
  305.             close(OUT);
  306.             exit;
  307.         }
  308.  
  309.         print OUT '(---G65 start---)'."\n";
  310.  
  311.         for($j=1;$j<=$kurikaeshi_suu;$j++){
  312.             print OUT '(---O'.$macro_No.' start---)'."\n";
  313.             modal_shori(4115,$macro_No);
  314.             hensuu_haki();
  315.             hikisuu_watashi($line);
  316.             for($i=0;$i<=$#macro;$i++){
  317.                 $_= $macro[$i];
  318.                 original_print($_);
  319.                 
  320.                 if(/^\s*\//){
  321.                     if($OBS_switch == 1){
  322.                     OBS_skip_print();
  323.                     next;
  324.                     }
  325.                     else{ $_= $'; }
  326.                 }
  327.  
  328.                 if(!/^\s*\%/){
  329.                     if(/^\s*(O[0-9]+)/){ print OUT '('.$1.')'.$'; }
  330.                     else{
  331.                         if(/^\s*N0*([0-9]+)/){
  332.                             modal_shori(4114,$1);
  333.                             $_= $';
  334.                         }
  335.                         if(/\(/){ $_= kakko_print($_); }
  336.                         shikaku_kakko_kensa($_);
  337.  
  338.                         if(/IF/){ $i= bunki_shori($_,$i,@macro); }
  339.                         elsif(/GOTO/){ $i= idou_shori($_,@macro); }
  340.                         elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$macro_No,@macro); }
  341.                         elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,$macro_No,@macro); }
  342.                         elsif(/^\s*G65/){
  343.                             $i= macro_G65($_,$i);
  344.                             modal_shori(4115,$macro_No);
  345.                         }
  346.                         elsif(/^\s*G66/){ $i= macro_G66($_,$i,$macro_No,@macro); }
  347.                         elsif(/^\s*M98/){
  348.                             $i= sub_M98($_,$i);
  349.                             modal_shori(4115,$macro_No);
  350.                         }
  351.                         else{
  352.                             $_= main_henkan($_);
  353.  
  354.                             if(/M99/){
  355.                                 $_= $`.$';
  356.                                 if(/[A-MO-Z]/){ extra_print($_); }
  357.                                 print OUT '(---O'.$macro_No.' end---)'."\n";
  358.                                 last;
  359.                             }
  360.                             elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  361.                             else{ extra_print($_); }
  362.                         }
  363.  
  364.                         if($i eq "M99"){
  365.                             print OUT '(---O'.$macro_No.' end---)'."\n";
  366.                             last;
  367.                         }
  368.                         elsif($i eq "M30" or $i eq "M02" or $i eq "M2"){ return $i; }
  369.                     }
  370.                 }
  371.             }
  372.         }
  373.         $macro_level--;
  374.         $yobidashi_tajuudo--;
  375.         print OUT '(---G65 end---)'."\n";
  376.         return $gyou;
  377.     }
  378.  
  379.     else{
  380.         print OUT $line;
  381.         print OUT '(---âvâìâOâëâÇö╘ìåé¬ÄwÆΦé│éΩé─éóé▄é╣é±---)'."\n";
  382.             close(OUT);
  383.             exit;
  384.     }
  385. }
  386.  
  387. sub macro_G66{
  388.     my ($line,$G66_start,$parent_prog_No,@prog)= @_;
  389.     my ($i,$j,$macro_No,$G66_end,$G66_flag,$kurikaeshi_suu,$idou_sequence,@macro);
  390.  
  391.     $line= main_henkan($line);
  392.     if($line =~ /P0*([0-9]+)/){
  393.         $macro_No= $1;
  394.  
  395.         if($line =~ /L([0-9]+)/){ $kurikaeshi_suu= $1; }
  396.         else{ $kurikaeshi_suu= 1; }
  397.  
  398.         $G66_flag= 1;
  399.         for($i=$G66_start+1;$i<=$#prog;$i++){
  400.             $_= $prog[$i];
  401.             if(/^\s*N?[0-9]*\s*G66/){ $G66_flag++; }
  402.             elsif(/^\s*N?[0-9]*\s*G67/){
  403.                 $G66_flag--;
  404.                 if($G66_flag == 0){
  405.                     $G66_end= $i;
  406.                     last;
  407.                 }
  408.             }
  409.         }
  410.  
  411.         if($prog[$i] !~ /\s*N?[0-9]*\s*G67/){
  412.             print OUT '(---G67é¬éáéΦé▄é╣é±---)'."\n";
  413.             close(OUT);
  414.             exit;
  415.         }
  416.  
  417.         @macro= prog_yomikomi($macro_No);
  418.         if(! defined(@macro)){
  419.             for($i=$G66_start;$i<=$G66_end;$i++){
  420.                 $_= $prog[$i];
  421.                 print OUT;
  422.             }
  423.             print OUT '(---O'.$macro_No.'é¬î⌐é┬é⌐éΦé▄é╣é±---)'."\n";
  424.             return $G66_end;
  425.         }
  426.  
  427.         print OUT '(---G66 modal mode --O'.$macro_No.'-- start---)'."\n";
  428.         $G66_modal_tajuudo++;
  429.         if($G66_modal_tajuudo == 1){ modal_shori(4012,66); }
  430.         G66_modal_touroku($G66_modal_tajuudo,$line,$macro_No,$kurikaeshi_suu,@macro);
  431.  
  432.         $macro_level++;
  433.         hensuu_haki();
  434.         hikisuu_watashi($line);
  435.         $macro_level--;
  436.  
  437.  
  438.         for($i=$G66_start+1;$i<=$G66_end-1;$i++){
  439.             $_= $prog[$i];
  440.             original_print($_);
  441.  
  442.             if(/^\s*\//){
  443.                 if($OBS_switch == 1){
  444.                     OBS_skip_print();
  445.                     next;
  446.                 }
  447.                 else{ $_= $'; }
  448.             }
  449.  
  450.             if(!/^\s*\%/){
  451.                 if(/^\s*N0*([0-9]+)/){
  452.                     modal_shori(4114,$1);
  453.                     $_= $';
  454.                 }
  455.                 if(/\(/){ $_= kakko_print($_); }
  456.                 shikaku_kakko_kensa($_);
  457.  
  458.                 if(/IF/){ $i= bunki_shori($_,$i,@prog); }
  459.                 elsif(/GOTO/){ $i= idou_shori($_,@prog); }
  460.                 elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$parent_prog_No,@prog); }
  461.                 elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,$parent_prog_No,@prog); }
  462.                 elsif(/^\s*N?[0-9]*\s*G65/){ 
  463.                     $i= macro_G65($_,$i);
  464.                     modal_shori(4115,$parent_prog_No);
  465.                 }
  466.                 elsif(/^\s*N?[0-9]*\s*G66/){
  467.                     $i= macro_G66($_,$i,$parent_prog_No,@prog);
  468.                 }
  469.                 elsif(/^\s*N?[0-9]*\s*M98/){
  470.                     $i= sub_M98($_,$i);
  471.                     modal_shori(4115,$parent_prog_No);
  472.                 }
  473.                 else{
  474.                     $_= main_henkan($_);
  475.  
  476.                     if(/M99/){
  477.                         $_= $`.$';
  478.                         if(/[A-MO-Z]/){
  479.                             extra_print($_);
  480.                         }
  481.                         last;
  482.                     }
  483.                     elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  484.                     else{ extra_print($_); }
  485.                 }
  486.  
  487.                 if($i eq "M99"){
  488.                     print OUT '(---O'.$prog_No.' end---)'."\n";
  489.                     return $i;
  490.                 }
  491.                 elsif($i eq "M30" or $i eq "M02" or $i eq "M2"){ return $i; }
  492.             }
  493.         }
  494.         print OUT '(---G66 modal mode --O'.$macro_No.'-- end---)'."\n";
  495.         $G66_modal_tajuudo--;
  496.         if($G66_modal_yobidashi == 0){ modal_shori(4012,67); }
  497.         return $G66_end;
  498.     }
  499.     else{
  500.         print OUT $line;
  501.         print OUT '(---âvâìâOâëâÇö╘ìåé¬ÄwÆΦé│éΩé─éóé▄é╣é±---)'."\n";
  502.             close(OUT);
  503.             exit;
  504.     }
  505. }
  506.  
  507. sub G66_modal_touroku{
  508.     my ($i,$line,$macro_No,$kurikaeshi_suu,@macro)= @_;
  509.  
  510.     $G66_line[$i]= $line;
  511.     $G66_macro_No[$i]= $macro_No;
  512.     $G66_kurikaeshi_suu[$i]= $kurikaeshi_suu; 
  513.     $G66_macro[$i]= \@macro;
  514. }
  515.  
  516. sub G66_modal_yobidashi{
  517.     my ($t)= @_;
  518.     my ($line,$macro_No,$kurikaeshi_suu)= ($G66_line[$t],$G66_macro_No[$t],$G66_kurikaeshi_suu[$t]);
  519.     my @macro= @{$G66_macro[$t]};
  520.     my ($i,$j,$parent_prog_No);
  521.     
  522.     $parent_prog_No= $value[4115];
  523.     $G66_yobidashi_tajuudo++;
  524.  
  525.     print OUT '(---G66 modal --O'.$macro_No.'-- start---)'."\n";
  526.     for($j=1;$j<=$kurikaeshi_suu;$j++){
  527.         $macro_level++;
  528.         $yobidashi_tajuudo++;
  529.         if($macro_level == 5){
  530.             print OUT '(---â}âNâìæ╜Ådôxé¬î└ôxé≡Æ┤éªé▄é╡é╜---)'."\n";
  531.             close(OUT);
  532.             exit;
  533.         }
  534.         if($yobidashi_tajuudo == 9){
  535.             print OUT '(---î─é╤Åoé╡æ╜Ådôxé¬î└ôxé≡Æ┤éªé▄é╡é╜---)'."\n";
  536.             close(OUT);
  537.             exit;
  538.         }
  539.  
  540.         print OUT '(---O'.$macro_No.' start---)'."\n";
  541.         modal_shori(4115,$macro_No);
  542.  
  543. #        hensuu_haki();
  544. #        hikisuu_watashi($line);
  545.  
  546.         for($i=0;$i<=$#macro;$i++){
  547.             $_= $macro[$i];
  548.             original_print($_);
  549.  
  550.             if(/^\s*\//){
  551.                 if($OBS_switch == 1){
  552.                     OBS_skip_print();
  553.                     next;
  554.                 }
  555.                 else{ $_= $'; }
  556.             }
  557.  
  558.             if(!/^\s*\%/){
  559.                 if(/^\s*(O[0-9]+)/){ print OUT '('.$1.')'.$'; }
  560.                 else{
  561.                     if(/^\s*N0*([0-9]+)/){
  562.                         modal_shori(4114,$1);
  563.                         $_= $';
  564.                     }
  565.                     if(/\(/){ $_= kakko_print($_); }
  566.                     shikaku_kakko_kensa($_);
  567.  
  568.                     if(/IF/){ $i= bunki_shori($_,$i,@macro); }
  569.                     elsif(/GOTO/){ $i= idou_shori($_,@macro); }
  570.                     elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$macro_No,@macro); }
  571.                     elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,@macro); }
  572.                     elsif(/^\s*G65/){
  573.                         $i= macro_G65($_,$i);
  574.                         modal_shori(4115,$macro_No);
  575.                     }
  576.                     elsif(/^\s*G66/){ $i= macro_G66($_,$i,$macro_No,@macro); }
  577.                     elsif(/^\s*M98/){
  578.                         $i= sub_M98($_,$i);
  579.                         modal_shori(4115,$macro_No);
  580.                     }
  581.                     else{
  582.                         $_= main_henkan($_);
  583.                         if(/M99/){
  584.                             $_= $`.$';
  585.                             if(/[A-MO-Z]/){ extra_print($_); }
  586.                             print OUT '(---O'.$macro_No.' end---)'."\n";
  587.                             last;
  588.                         }
  589.                         elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  590.                         else{ extra_print($_); }
  591.                     }
  592.  
  593.                     if($i eq "M99"){
  594.                         print OUT '(---O'.$macro_No.' end---)'."\n";
  595.                         last;
  596.                     }
  597.                     elsif($i eq "M30" or $i eq "M02" or $i eq "M2"){ return $i; }
  598.                 }
  599.             }
  600.         }
  601.         $macro_level--;
  602.         $yobidashi_tajuudo--;
  603.     }
  604.     print OUT '(---G66 modal --O'.$macro_No.'-- end---)'."\n";
  605.     $G66_yobidashi_tajuudo--;
  606.     modal_shori(4115,$parent_prog_No);
  607. }
  608.  
  609. sub sub_M98{
  610.     my ($line,$gyou)= @_;
  611.     my ($i,$j,$k,$kurikaeshi_suu,$prog_No,$jikkou_bun,$comment,@sub);
  612.  
  613.     $_= main_henkan($line);
  614.     if(/M98\s*P([0-9]+)\s*/){
  615.         $jikkou_bun= $`.$';
  616.         if($M98_houshiki == 0){
  617.             $prog_No= $1;
  618.  
  619.             if($jikkou_bun =~ /L([0-9]+)/){
  620.                 $jikkou_bun= $`.$';
  621.                 $kurikaeshi_suu= $1;
  622.             }
  623.             else{ $kurikaeshi_suu= 1; }
  624.         }
  625.         else{
  626.             if(length($1) <= 4){
  627.                 $prog_No= $1;
  628.                 if($jikkou_bun =~ /L([0-9]+)/){
  629.                     $jikkou_bun= $`.$';
  630.                     $kurikaeshi_suu= $1;
  631.                 }
  632.                 else{ $kurikaeshi_suu= 1; }
  633.             }
  634.             else{
  635.                 $under_line= $1;
  636.                 if($under_line =~ /(.+)(.{4})$/){
  637.                     $kurikaeshi_suu= $1;
  638.                     $prog_No= $2;
  639.                 }
  640.             }
  641.         }
  642.  
  643.         $prog_No =~ s/^0+//;
  644.         if($jikkou_bun =~ /[A-KMO-Z]/){
  645.             $jikkou_bun= main_henkan($jikkou_bun);
  646.             extra_print($jikkou_bun);
  647.         }
  648.  
  649.         @sub= prog_yomikomi($prog_No);
  650.         if(! defined(@sub)){
  651.             print OUT $line;
  652.             print OUT '(---O'.$prog_No.'é¬î⌐é┬é⌐éΦé▄é╣é±---)'."\n";
  653.             return $gyou;
  654.         }
  655.  
  656.         $yobidashi_tajuudo++;
  657.         if($yobidashi_tajuudo == 9){
  658.             print OUT '(---î─é╤Åoé╡æ╜Ådôxé¬î└ôxé≡Æ┤éªé▄é╡é╜---)'."\n";
  659.             close(OUT);
  660.             exit;
  661.         }
  662.  
  663.         print OUT '(---M98 start---)'."\n";
  664.         for($j=1;$j<=$kurikaeshi_suu;$j++){;
  665.             print OUT '(---O'.$prog_No.' start---)'."\n";
  666.             modal_shori(4115,$prog_No);
  667.             for($i=0;$i<=$#sub;$i++){
  668.                 $_= $sub[$i];
  669.                 original_print($_);
  670.  
  671.                 if(/^\s*\//){
  672.                     if($OBS_switch == 1){
  673.                         OBS_skip_print();
  674.                         next;
  675.                     }
  676.                     else{ $_= $'; }
  677.                 }
  678.  
  679.                 if(!/^\s*\%/){
  680.                     if(/^\s*(O[0-9]+)/){ print OUT '('.$1.')'.$'; }
  681.                     else{
  682.                         if(/^\s*N0*([0-9]+)/){
  683.                             modal_shori(4114,$1);
  684.                             $_= $';
  685.                         }
  686.                         if(/\(/){ $_= kakko_print($_); }
  687.                         shikaku_kakko_kensa($_);
  688.  
  689.                         if(/IF/){ $i= bunki_shori($_,$i,@sub); }
  690.                         elsif(/GOTO/){ $i= idou_shori($_,@sub); }
  691.                         elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$prog_No,@sub); }
  692.                         elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,$prog_No,@sub); }
  693.                         elsif(/^\s*G65/){
  694.                             $i= macro_G65($_,$i);
  695.                             modal_shori(4115,$prog_No);
  696.                         }
  697.                         elsif(/^\s*G66/){ $i= macro_G66($_,$i,$prog_No,@sub); }
  698.                         elsif(/^\s*M98/){
  699.                             $i= sub_M98($_,$i);
  700.                             modal_shori(4115,$prog_No);
  701.                         }
  702.                         else{
  703.                             $_= main_henkan($_);
  704.                             if(/M99/){
  705.                                 $_= $`.$';
  706.                                 if(/[A-MO-Z]/){ extra_print($_); }
  707.                                 print OUT '(---O'.$prog_No.' end---)'."\n";
  708.                                 last;
  709.                             }
  710.                             elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  711.                             else{ extra_print($_); }
  712.                         }
  713.  
  714.                         if($i eq "M99"){
  715.                             print OUT '(---O'.$prog_No.' end---)'."\n";
  716.                             last;
  717.                         }
  718.                         elsif($i eq "M30" or $i eq "M02" or $i eq "M2"){ return $i; }
  719.                     }
  720.                 }
  721.             }
  722.         }
  723.         print OUT '(---M98 end---)'."\n";
  724.         $yobidashi_tajuudo--;
  725.         return $gyou;
  726.     }
  727.     else{
  728.         print OUT $line;
  729.         print OUT '(---âvâìâOâëâÇö╘ìåé¬ÄwÆΦé│éΩé─éóé▄é╣é±---)'."\n";
  730.         close(OUT);
  731.         exit;
  732.     }
  733. }
  734.  
  735. sub idou_shori{
  736.     my ($line,@prog)= @_;
  737.     my ($i,$idou_sequence);
  738.     
  739.     $_= main_henkan($line);
  740.     if(/GOTO\s*0*([0-9]+)/){
  741.         $idou_sequence= $1;
  742.         for($i=0;$i<=$#prog;$i++){
  743.             if($prog[$i] =~ /^\s*N0*([0-9]+)/){
  744.                 if($1 == $idou_sequence){
  745.                     if($debug_flag == 1){ print OUT '(---move to N' . $idou_sequence .'---)'."\n"; }
  746.                     return ($i - 1);
  747.                 }
  748.             }
  749.         }
  750.         
  751.         print OUT '(---N'.$idou_sequence.'é¬éáéΦé▄é╣é±---)'."\n";
  752.         close(OUT);
  753.         exit;
  754.     }
  755.     else{
  756.         print OUT '(---GOTOì\ò╢é¬É│é╡é¡éáéΦé▄é╣é±---'."\n";
  757.         close(OUT);
  758.         exit;
  759.     }
  760. }
  761.  
  762. sub bunki_shori{
  763.     my ($line,$gyou,@prog)= @_;
  764.     my ($joukenshiki,$jikkoubun,$flag);
  765.     
  766.     $_= $line;
  767.     if(/IF\s*\[\s*(.+)\s*\]\s*(GOTO\s*)/){
  768.         ($joukenshiki,$jikkoubun)= ($1,$2.$');
  769.         $flag= jouken_handan($joukenshiki);
  770.         if($flag == 1){
  771.             if($debug_flag == 1){ print OUT '(---true---)'."\n"; }
  772.             $gyou= idou_shori($jikkoubun,@prog);
  773.             return $gyou;
  774.         }
  775.         else{
  776.             if($debug_flag == 1){ print OUT '(---false---)'."\n"; }
  777.             return $gyou;
  778.         }
  779.     }
  780.     elsif(/IF\s*\[\s*(.+)\s*\]\s*THEN\s*/){
  781.         ($joukenshiki,$jikkoubun)= ($1,$');
  782.         $flag= jouken_handan($joukenshiki);
  783.         if($flag == 1){
  784.             if($debug_flag == 1){ print OUT '(---true---)'."\n"; }
  785.             $_= main_henkan($jikkoubun); 
  786.             if(/M99/){
  787.                 $_= $`.$';
  788.                 if(/[A-Z]/){ extra_print($_); }
  789.                 return "M99";
  790.             }
  791.             elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  792.             else{ extra_print($_); }
  793.             return $gyou;
  794.         }
  795.         else{
  796.             if($debug_flag == 1){ print OUT '(---false---)'."\n"; }
  797.             return $gyou;
  798.         }
  799.     }
  800.     else{
  801.         print OUT '(---IFì\ò╢é¬É│é╡é¡éáéΦé▄é╣é±---'."\n";
  802.         return $gyou;
  803.     }
  804. }
  805.  
  806. sub kurikaeshi_shori{
  807.     my ($line,$while_start,$parent_prog_No,@prog)= @_;
  808.     my ($i,$while_end,$joukenshiki,$shikibetsu_bangou);
  809.  
  810.     $_= $line;
  811.     if(/WHILE\s*\[\s*(.+)\s*\]\s*DO\s*([123])/){
  812.         ($joukenshiki,$shikibetsu_bangou)= ($1,$2);
  813.  
  814.         for($i=$while_start+1;$i<=$#prog;$i++){
  815.             $_= $prog[$i];
  816.             if(/^\s*N?[0-9]*\s*END\s*$shikibetsu_bangou/){
  817.                 $while_end= $i;
  818.                 last;
  819.             }
  820.         }
  821.         if(! defined($while_end)){
  822.             print OUT '(---END'.$shikibetsu_bangou.'é¬éáéΦé▄é╣é±---)'."\n";
  823.             close(OUT);
  824.             exit;
  825.         }
  826.         
  827.         for(;;){
  828.             $flag= jouken_handan($joukenshiki);
  829.  
  830.             if($flag == 0){
  831.                 if($debug_flag == 1){ print OUT '(---DO'.$shikibetsu_bangou.' false---)'."\n"; }
  832.                 return $while_end;
  833.             }
  834.             if($debug_flag == 1){ print OUT '(---DO'.$shikibetsu_bangou.' true---)'."\n"; }
  835.             for($i=$while_start+1;$i<=$while_end-1;$i++){
  836.                 $_= $prog[$i];
  837.                 original_print($_);
  838.  
  839.                 if(/^\s*\//){
  840.                     if($OBS_switch == 1){
  841.                         OBS_skip_print();
  842.                         next;
  843.                     }
  844.                     else{ $_= $'; }
  845.                 }
  846.  
  847.                 if(/^\s*N0*([0-9]+)/){
  848.                     modal_shori(4114,$1);
  849.                     $_= $';
  850.                 }
  851.                 if(/\(/){ $_= kakko_print($_); }
  852.                 shikaku_kakko_kensa($_);
  853.  
  854.                 if(/IF/){ $i= bunki_shori($_,$i,@prog); }
  855.                 elsif(/GOTO/){ $i= idou_shori($_,@prog); }
  856.                 elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$parent_prog_No,@prog); }
  857.                 elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,$parent_prog_No,@prog); }
  858.                 elsif(/^\s*G65/){
  859.                     $i= macro_G65($_,$i);
  860.                     modal_shori(4115,$parent_prog_No);
  861.                 }
  862.                 elsif(/^\s*N?[0-9]*\s*G66/){ $i= macro_G66($_,$i,$parent_prog_No,@prog); }
  863.                 elsif(/^\s*N?[0-9]*\s*M98/){
  864.                     $i= sub_M98($_,$i);
  865.                     modal_shori(4115,$parent_prog_No);
  866.                 }
  867.                 else{
  868.                     $_= main_henkan($_);
  869.                     if(/M99/){
  870.                         $_= $`.$';
  871.                         if(/[A-Z]/){ extra_print($_); }
  872.                         return "M99";
  873.                     }
  874.                     elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  875.                     else{ extra_print($_); }
  876.                 }
  877.  
  878.                 if($i > $while_end){ return $i; }
  879.                 elsif($i eq "M99" or $i eq "M30" or $i eq "M02" or $i eq "M2"){ return $i; }
  880.             }
  881.         }
  882.     }
  883.     else{
  884.         print OUT '(---WHILEì\ò╢é¬É│é╡é¡éáéΦé▄é╣é±---)'."\n";
  885.         return $while_start;
  886.     }
  887. }
  888.  
  889. sub jouken_handan{
  890.     ($line)= @_;
  891.     my ($pre_line,$post_line,$pre_pre_line,$post_post_line,$copy_pre_line,$reverse_post_line);
  892.     my ($sahen,$jouken,$uhen,$flag);
  893.     my ($hiraki_kakko,$toji_kakko,$length,$char,$i);
  894.  
  895.     $line= '['.$line.']';
  896.     while($line =~ /\s*(EQ)\s*/ or $line =~ /\s*(NE)\s*/ or $line =~ /\s*(GT)\s*/ or $line =~ /\s*(LT)\s*/ or $line =~ /\s*(GE)\s*/ or $line =~ /\s*(LE)\s*/){
  897.         $jouken= $1;
  898.         ($pre_line,$copy_pre_line,$post_line)= ($`,$`,$');
  899.         $reverse_post_line= reverse($post_line);
  900.         ($hiraki_kakko,$toji_kakko)= (0,0);
  901.  
  902.         $length= length($pre_line);
  903.         for($i=1;$i<=$length;$i++){
  904.             $char= chop($copy_pre_line);
  905.             if($char eq '['){ $hiraki_kakko++; }
  906.             if($char eq ']'){ $hiraki_kakko--; }
  907.             if($hiraki_kakko == 1){
  908.                 $sahen= substr($pre_line,-$i);
  909.                 $pre_pre_line= substr($pre_line,0,-$i);
  910.                 last;
  911.             }
  912.         }
  913.  
  914.         $length= length($post_line);
  915.         for($i=1;$i<=$length;$i++){
  916.             $char= chop($reverse_post_line);
  917.             if($char eq ']'){ $toji_kakko++; }
  918.             if($char eq '['){ $toji_kakko--; }
  919.             if($toji_kakko == 1){ 
  920.                 $uhen= substr($post_line,0,$i);
  921.                 $post_post_line= substr($post_line,$i);
  922.                 last;
  923.             }
  924.         }
  925.         $flag= kobetsu_jouken_handan($sahen,$jouken,$uhen);
  926.         $line= $pre_pre_line.$flag.$post_post_line;
  927.     }
  928.     $line= main_henkan($line);
  929.     return $line;
  930. }
  931.  
  932. sub kobetsu_jouken_handan{
  933.     my ($sahen,$jouken,$uhen)= @_;
  934.     my ($flag);
  935.  
  936.     $sahen= substr($sahen,1);
  937.     $sahen= joukennai_henkan($sahen,$jouken);
  938.     $uhen= substr($uhen,0,-1);
  939.     $uhen= joukennai_henkan($uhen,$jouken);
  940.  
  941.     if($jouken eq "EQ"){
  942.         if($sahen eq '(undefined)'){
  943.             if($uhen eq '(undefined)'){ $flag= 1; }
  944.             else{ $flag= 0; }
  945.         }
  946.         elsif($uhen eq '(undefined)'){ $flag= 0; }
  947.         elsif($sahen == $uhen){ $flag= 1; }
  948.         else{ $flag= 0; }
  949.     }
  950.     elsif($jouken eq "NE"){
  951.         if($sahen eq '(undefined)'){
  952.             if($uhen ne '(undefined)'){ $flag= 1; }
  953.             else{ $flag= 0; }
  954.         }
  955.         elsif($uhen eq '(undefined)'){ $flag= 1; }
  956.         elsif($sahen != $uhen){ $flag= 1; }
  957.         else{ $flag= 0; }
  958.     }
  959.     elsif($jouken eq "GT"){
  960.         if($sahen > $uhen){ $flag= 1; }
  961.         else{ $flag= 0; }
  962.     }
  963.     elsif($jouken eq "LT"){
  964.         if($sahen < $uhen){ $flag= 1; }
  965.         else{ $flag= 0; }
  966.     }
  967.     elsif($jouken eq "GE"){
  968.         if($sahen >= $uhen){ $flag= 1; }
  969.         else{ $flag= 0; }
  970.     }
  971.     elsif($jouken eq "LE"){
  972.         if($sahen <= $uhen){ $flag= 1; }
  973.         else{ $flag= 0; }
  974.     }
  975.     return $flag;
  976. }
  977.  
  978. sub joukennai_henkan{
  979.     ($_,$jouken)= @_;
  980.     $_= main_henkan($_);
  981.     while(/\#[0-9\.]+/){
  982.         ($pre_line,$post_line)= ($`,$');
  983.         if($jouken eq "EQ" or $jouken eq "NE"){
  984.             if(/^\s*\#([0-9\.]+)\s*$/){
  985.                 if($1 <= 33){
  986.                     if(! defined($local_value[$macro_level][$1])){ $_= '(undefined)'; }
  987.                     else{ $_= $pre_line.$local_value[$macro_level][$1].$post_line; }
  988.                 }
  989.                 else{
  990.                     if(! defined($value[$1])){ $_= '(undefined)'; }
  991.                     else{ $_= $pre_line.$value[$1].$post_line; }
  992.                 }
  993.             }
  994.             else{
  995.                 $_= $pre_line."0".$post_line;
  996.                 $_= main_henkan($_);
  997.             }
  998.         }
  999.         else{
  1000.             $_= $pre_line."0".$post_line;
  1001.             $_= main_henkan($_);
  1002.         }
  1003.     }
  1004.     return $_;
  1005. }
  1006.  
  1007. sub kurikaeshi_shori2{
  1008.     my ($line,$do_start,$parent_prog_No,@prog)= @_;
  1009.     my ($i,$do_end,$joukenshiki,$shikibetsu_bangou);
  1010.     
  1011.     $_= $line;
  1012.     if(/DO\s*([123])/){
  1013.         $shikibetsu_bangou= $1;
  1014.  
  1015.         for($i=$do_start+1;$i<=$#prog;$i++){
  1016.             $_= $prog[$i];
  1017.             if(/^\s*N?[0-9]*\s*END\s*$shikibetsu_bangou/){
  1018.                 $do_end= $i;
  1019.                 last;
  1020.             }
  1021.         }
  1022.         if(! defined($do_end)){
  1023.             print OUT '(---END'.$shikibetsu_bangou.'é¬éáéΦé▄é╣é±---)'."\n";
  1024.             close(OUT);
  1025.             exit;
  1026.         }
  1027.  
  1028.         for(;;){
  1029.             for($i=$do_start+1;$i<=$do_end-1;$i++){
  1030.                 $_= $prog[$i];
  1031.                 original_print($_);
  1032.  
  1033.                 if(/^\s*\//){
  1034.                     if($OBS_switch == 1){
  1035.                         OBS_skip_print();
  1036.                         next;
  1037.                     }
  1038.                     else{ $_= $'; }
  1039.                 }
  1040.  
  1041.                 if(/^\s*N0*([0-9]+)/){
  1042.                     modal_shori(4114,$1);
  1043.                     $_= $';
  1044.                 }
  1045.                 if(/\(/){ $_= kakko_print($_); }
  1046.                 shikaku_kakko_kensa($_);
  1047.  
  1048.                 if(/IF/){ $i= bunki_shori($_,$i,@prog); }
  1049.                 elsif(/GOTO/){ $i = idou_shori($_,@prog); }
  1050.                 elsif(/WHILE/){ $i= kurikaeshi_shori($_,$i,$parent_prog_No,@prog); }
  1051.                 elsif(/DO/){ $i= kurikaeshi_shori2($_,$i,$parent_prog_No,@prog); }
  1052.                 elsif(/^\s*G65/){
  1053.                     $i= macro_G65($_,$i);
  1054.                     modal_shori(4115,$parent_prog_No);
  1055.                 }
  1056.                 elsif(/^\s*G66/){ $i= macro_G66($_,$i,$parent_prog_No,@prog); }
  1057.                 elsif(/^\s*M98/){
  1058.                     $i= sub_M98($_,$i);
  1059.                     modal_shori(4115,$parent_prog_No);
  1060.                 }
  1061.                 else{
  1062.                     $_= main_henkan($_);
  1063.  
  1064.                     if(/M99/){
  1065.                         $_= $`.$';
  1066.                         if(/[A-Z]/){ extra_print($_); }
  1067.                         return "M99";
  1068.                     }
  1069.                     elsif(/(M30)/ or /(M0?2)[A-Z\s]/){ return $1; }
  1070.                     else{ extra_print($_); }
  1071.                 }
  1072.  
  1073.                 if($i > $do_end){ return $i; }
  1074.                 elsif($i eq "M99" or $i eq "M30" or $i eq "M02" or $i eq "M2"){ return $i; }
  1075.             }
  1076.         }
  1077.     }
  1078.     else{ return $do_start; }
  1079. }
  1080.  
  1081. sub main_henkan{
  1082.     ($_)= @_;
  1083.     my $i;
  1084.     for($i=1;$i<=6;$i++){
  1085.         $_= hensuu_henkan($_);
  1086.         $_= shisoku_enzan($_);
  1087.         $_= kansuu_henkan($_);
  1088.         $_= kakko_jokyo($_);
  1089.         $_= bit_enzan($_);
  1090.     }
  1091.     $_= toushiki_shori($_);
  1092.     $_= miteigi_shori($_);
  1093.     return $_;
  1094. }
  1095.  
  1096. sub hensuu_henkan{
  1097.     ($line)= @_;
  1098.     my $new_line= "";
  1099.  
  1100.     if($line =~ /\s*\=\s*/){
  1101.         $new_line= $`.$&;
  1102.         $line= $';
  1103.     }
  1104.     while($line =~ /\#([0-9]+)/){
  1105.         ($pre_line,$apply_line,$line,$hensuu_No)= ($`,$&,$',$1);
  1106.         $new_line= $new_line.$pre_line;
  1107.         if($pre_line =~ /.$/){ $last_char= $&; }
  1108.         else{ $last_char= ''; }
  1109.  
  1110.         if($hensuu_No <= 33){
  1111.             if(defined($local_value[$macro_level][$hensuu_No])){
  1112.                 if($last_char =~ /[GMSTPDH]/){ 
  1113.                     $new_line= $new_line.round($local_value[$macro_level][$hensuu_No]);
  1114.                 }
  1115.                 else{
  1116.                     $new_line= $new_line.$local_value[$macro_level][$hensuu_No];
  1117.                 }
  1118.             }
  1119.             else{ $new_line= $new_line.$apply_line; }
  1120.         }
  1121.         else{
  1122.             if(defined($value[$hensuu_No])){
  1123.                 if($last_char =~ /[GMSTPDH]/){
  1124.                     $new_line= $new_line.round($value[$hensuu_No]);
  1125.                 }
  1126.                 else{
  1127.                     $new_line= $new_line.$value[$hensuu_No];
  1128.                 }
  1129.             }
  1130.             else{ $new_line= $new_line.$apply_line; }
  1131.         }
  1132.     }
  1133.     $new_line= $new_line.$line;
  1134.     return $new_line;
  1135. }
  1136.  
  1137. sub shisoku_enzan{
  1138.     ($_)= @_;
  1139.     my $jozan_flag;
  1140.     
  1141.     while(/\#\s*(\-?)\s*\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`."\#".$1.$2.$'; }
  1142.     while(/\-\s*\-/g){
  1143.         ($pre_line,$post_line)= ($`,$');
  1144.         if($pre_line =~ /[0-9\.\]]\s*$/){ $_= $pre_line."\+".$post_line; }
  1145.         else{ $_= $pre_line.$post_line; }
  1146.     }
  1147. #    while(/(\-?[0-9\.]+)\s*\*\s*(\-?[0-9\.]+)/g){
  1148.     while(/([0-9\.]+)\s*\*\s*(\-?[0-9\.]+)/g){
  1149.         ($pre_line,$post_line,$num1,$num2)= ($`,$',$1,$2);
  1150.         if($pre_line =~ /\/\s*$/){ $jozan_flag= 1; }
  1151.         elsif($pre_line !~ /\#\-?$/){ $_= $pre_line.naibu_marume($num1*$num2).$post_line; }
  1152.     }
  1153. #    while(/(\-?[0-9\.]+)\s*\/\s*(\-?[0-9\.]+)/g){
  1154.     while(/([0-9\.]+)\s*\/\s*(\-?[0-9\.]+)/g){
  1155.         ($pre_line,$post_line,$num1,$num2)= ($`,$',$1,$2);
  1156.         if($pre_line !~ /\#\-?$/){ $_= $pre_line.naibu_marume($num1/$num2).$post_line; }
  1157.     }
  1158.     if($jozan_flag == 1){
  1159.         while(/([0-9\.]+)\s*\*\s*(\-?[0-9\.]+)/g){
  1160.             ($pre_line,$post_line,$num1,$num2)= ($`,$',$1,$2);
  1161.             if($pre_line !~ /\#\-?$/ and $pre_line !~ /\/\s*$/){ $_= $pre_line.naibu_marume($num1*$num2).$post_line; }
  1162.         }
  1163.     }
  1164. #    while(/((\-?)[0-9\.]+)\s*\-\s*(\-?[0-9\.]+)/g){
  1165. #        ($pre_line,$post_line,$num1,$num2)= ($`,$',$1,$2);
  1166. #        if($pre_line !~ /\#$/ and $post_line !~ /^\s*[\*\/]/){ $_= $pre_line.kagenzan($num1,$num2,'-').$post_line; }
  1167. #    }
  1168. #    while(/(\-?[0-9\.]+)\s*\+\s*(\-?[0-9\.]+)/g){
  1169. #        ($pre_line,$post_line,$num1,$num2)= ($`,$',$1,$2);
  1170. #        if($pre_line !~ /\#$/ and $post_line !~ /^\s*[\*\/]/){ $_= $pre_line.kagenzan($num1,$num2).$post_line; }
  1171. #    }
  1172.     while(/((\-?)[0-9\.]+)\s*\-\s*(\-?[0-9\.]+)/g){
  1173.         ($pre_line,$post_line,$num1,$fugou,$num2)= ($`,$',$1,$2,$3);
  1174.         if($fugou ne ''){ $fugou = '+'; }
  1175.         else{ $fugou = ''; }
  1176.         
  1177.         if($pre_line !~ /\#$/ and $post_line !~ /^\s*[\*\/]/){ $_= $pre_line.$fugou.kagenzan($num1,$num2,'-').$post_line; }
  1178.     }
  1179.     while(/((\-?)[0-9\.]+)\s*\+\s*(\-?[0-9\.]+)/g){
  1180.         ($pre_line,$post_line,$num1,$fugou,$num2)= ($`,$',$1,$2,$3);
  1181.         if($fugou ne ''){ $fugou = '+'; }
  1182.         else{ $fugou = ''; }
  1183.         
  1184.         if($pre_line !~ /\#$/ and $post_line !~ /^\s*[\*\/]/){ $_= $pre_line.$fugou.kagenzan($num1,$num2).$post_line; }
  1185.     }
  1186.     while(/\+\-/g){
  1187.         $_ = $`.'-'.$';
  1188.     }
  1189.     
  1190.     return $_;
  1191. }
  1192.  
  1193. sub kansuu_henkan{
  1194.     ($_)= @_;
  1195.     while(/ABS\[\s*\-?([0-9\.]+)\s*\]/g){ $_= $`.naibu_marume($1).$'; }
  1196.     while(/SQRT\[\s*([0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(sqrt($1)).$'; }
  1197.     while(/SIN\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(sin($1/$RAD)).$'; }
  1198.     while(/COS\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(cos($1/$RAD)).$'; }
  1199.     while(/TAN\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(sin($1/$RAD)/cos($1/$RAD)).$'; }
  1200.     while(/ATAN\[\s*(\-?[0-9\.]+)\s*\]\/\[\s*(\-?[0-9\.]+)\s*\]/g){
  1201.         $_= $`.naibu_marume(atan2($1,$2)*$RAD).$';
  1202.     }
  1203.     while(/ROUND\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(round($1)).$'; }
  1204.     while(/FUP\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(fup($1)).$'; }
  1205.     while(/FIX\[\s*(\-?[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(int($1)).$'; }
  1206.     while(/BCD\[\s*(\[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(bcd_shori($1)).$'; }
  1207.     while(/BIN\[\s*(\[0-9\.]+)\s*\]/g){ $_= $`.naibu_marume(bin_shori($1)).$'; }
  1208.     return $_;
  1209. }
  1210.  
  1211. sub kakko_jokyo{
  1212.     ($_)= @_;
  1213.     my ($line,$new_line)= ($_,"");
  1214.     while($line =~ /(\-?)\s*\[\s*(\-?[0-9\.]+)\s*\]/){
  1215.         ($_,$num1,$num2,$line)= ($`,$1,$2,$');
  1216.         $apply_line= $&;
  1217.         $new_line= $new_line.$_;
  1218.         if(/.$/){ $char= $&; }
  1219.         if(!/SIN$/ and !/COS$/ and !/TAN$/ and !/ATAN$/ and !/ATAN\[\s*\-?[0-9\.]+\s*\]\/$/ and !/ABS$/ and !/SQRT$/ and !/ROUND$/ and !/FIX$/ and !/FUP$/ and !/BCD$/ and !/BIN$/){
  1220.             if($char =~ /[GMSTPDH]/){
  1221.                 if($num1 =~ /\-/){
  1222.                     if($num2 =~ /^\-(.+)/){ $new_line= $new_line.round($1); }
  1223.                     else{ $new_line= $new_line.round($num2); }
  1224.                 }
  1225.                 else{ $new_line= $new_line.round($num2); }
  1226.             }
  1227.             else{ $new_line= $new_line.$num1.$num2; }
  1228.         }
  1229.         else{ $new_line= $new_line.$apply_line; }
  1230.     }
  1231.     $new_line= $new_line.$line;
  1232.     return $new_line;
  1233. }
  1234.  
  1235. sub bit_enzan{
  1236.     ($_)= @_;
  1237.     while(/(.?)\s*([0-9\.]+)\s*AND\s*([0-9\.]+)/g){
  1238.         if($1 ne '#'){ $_= $`.$1.naibu_marume(and_shori($2,$3)).$'; }
  1239.     }
  1240.     while(/(.?)\s*([0-9\.]+)\s*OR\s*([0-9\.]+)/g){
  1241.         if($1 ne '#'){ $_= $`.$1.naibu_marume(or_shori($2,$3)).$'; }
  1242.     }
  1243.     while(/(.?)\s*([0-9\.]+)\s*XOR\s*([0-9\.]+)/g){
  1244.         if($1 ne '#'){ $_= $`.$1.naibu_marume(xor_shori($2,$3)).$'; }
  1245.     }
  1246.     return $_;
  1247. }
  1248.  
  1249. sub toushiki_shori{
  1250.     ($_)= @_;
  1251.     my ($hensuu_No1,$hensuu_No2,$uhen);
  1252.     if(/^\s*N?[0-9]*\s*\#([0-9\.]+)\s*\=\s*/){
  1253.         ($hensuu_No1,$uhen)= ($1,$');
  1254.         if($uhen =~ /^\s*(\-?[0-9\.]+)\s*$/){
  1255.             if($hensuu_No1 <= 33){
  1256.                 $local_value[$macro_level][$hensuu_No1]= $1;
  1257.                 if($debug_flag == 1){ print OUT '(---#'.$hensuu_No1.'= '.$1.'---)'."\n"; }
  1258.             }
  1259.             else{
  1260.                 if($hensuu_No1 == 3000){
  1261.                     $alerm_No= 3000+$1;
  1262.                     print OUT '(---âAâëü[âÇö╘ìå '.$alerm_No.'---)'."\n";
  1263.                     close(OUT);
  1264.                     exit;
  1265.                 }
  1266.                 else{
  1267.                     $value[$hensuu_No1]= $1;
  1268.                     if($debug_flag == 1){ print OUT '(---#'.$hensuu_No1.'= '.$1.'---)'."\n"; }
  1269.                 }
  1270.             }
  1271.             $_= "";
  1272.         }
  1273.         elsif($uhen =~ /^\s*\#([0-9\.]+)\s*$/){
  1274.             if($hensuu_No2 <= 33){
  1275.                 if(! defined($local_value[$macro_level][$hensuu_No2])){
  1276.                     if($hensuu_No1 <= 33){
  1277.                         undef($local_value[$macro_level][$hensuu_No1]);
  1278.                         if($debug_flag == 1){ print OUT '(---#'.$hensuu_No1.'= <ï≤>---)'."\n"; }
  1279.                     }
  1280.                     else{
  1281.                         undef($value[$hensuu_No1]);
  1282.                         if($debug_flag == 1){ print OUT '(---#'.$hensuu_No1.'= <ï≤>---)'."\n"; }
  1283.                     }
  1284.                 }
  1285.             }
  1286.             else{
  1287.                 if(! defined($value[$hensuu_No2])){
  1288.                     if($hensuu_No1 <= 33){
  1289.                         undef($local_value[$macro_level][$hensuu_No1]);
  1290.                         if($debug_flag == 1){ print OUT '(---#'.$hensuu_No1.'= <ï≤>---)'."\n"; }
  1291.                     }
  1292.                     else{
  1293.                         undef($value[$hensuu_No1]);
  1294.                         if($debug_flag == 1){ print OUT '(---#'.$hensuu_No1.'= <ï≤>---)'."\n"; }
  1295.                     }
  1296.                 }
  1297.             }
  1298.             ($_,$uhen)= ("","");
  1299.         }
  1300.         else{
  1301.             while($uhen =~ /\#([0-9\.]+)/g){
  1302.                 ($pre_line,$hensuu_No2,$post_line)= ($`,$1,$');
  1303.                 $uhen= $pre_line.'0'.$post_line;
  1304.             }
  1305.             $_= "\#".$hensuu_No1."\=".$uhen;
  1306.             $_= main_henkan($_);
  1307.         }
  1308.     }
  1309.     return $_;
  1310. }
  1311.  
  1312. sub miteigi_shori{
  1313.     ($_)= @_;
  1314.     my $new_line= "";
  1315.  
  1316.     while(/[A-Z]\#([0-9\.]+)\s*([A-Z]?)/){
  1317.         ($pre_line,$post_line,$hensuu_No,$last_char)= ($`,$',$1,$2);
  1318.  
  1319.         if($hensuu_No <= 33){
  1320.             if(! defined($local_value[$macro_level][$hensuu_No])){
  1321.                 $_= $pre_line.$last_char.$post_line;
  1322.             }
  1323.         }
  1324.         else{
  1325.             if(! defined($value[$hensuu_No])){
  1326.                 $_= $pre_line.$last_char.$post_line;
  1327.             }
  1328.         }
  1329.     }
  1330.  
  1331.     if(/\#([0-9\.]+)/){
  1332.         while(/\#([0-9\.]+)/){
  1333.             ($pre_line,$post_line,$hensuu_No)= ($`,$',$1);
  1334.             $_= $pre_line.'0'.$post_line;
  1335.         }
  1336.         $_= main_henkan($_);
  1337.     }
  1338.  
  1339.     return $_;
  1340. }
  1341.  
  1342. sub kagenzan{
  1343.     my ($num1,$num2,$enzanshi)= @_;
  1344.     my $num;
  1345.     $num1= naibu_marume($num1);
  1346.     $num2= naibu_marume($num2);
  1347.     if($enzanshi eq '-'){ $num= $num1 - $num2; }
  1348.     else{ $num= $num1 + $num2; }
  1349.     #if($num !~ /\./ and $num != 0){ $num= $num.'.'; }
  1350.     return $num;
  1351. }
  1352.  
  1353. sub modal_shori{
  1354.     my ($No,$num)= @_;
  1355.     $value[$No]= $num;
  1356.     $value[$No+200]= $num;
  1357.     if($modal_flag == 1){ print OUT '(----#'.$No.'= '.$num.'----)'."\n"; }
  1358. }
  1359.  
  1360. #sub original_print{
  1361. #    my ($line)= @_;
  1362. #    $line =~ s/\s*$//;
  1363. #    if($line ne ""){
  1364. #        if($debug_flag == 1){ print OUT '(^^ '.$line.' ^^)'."\n"; }
  1365. #    }
  1366. #}
  1367.  
  1368. sub original_print{
  1369.     ($_)= @_;
  1370.     my $original= $_;
  1371.  
  1372.     $_ =~ s/\s*$//;
  1373.     if($_ ne "" and $debug_flag == 1){
  1374.         if( (!/^N?[0-9]*\s*\(/) or (!/\)$/) ){
  1375.             #if(/[\[\#\=\*\/]/ or /DO/ or /GOTO/ or /G65/ or /G66/ or /M98/){
  1376.             if(/[\[\#\=\*\/]/ or /DO/ or /GOTO/ or /G65/ or /G66/ or /M98/ or /N[0-9]+/){
  1377.                 print OUT '(^^ '.$_.' ^^)'."\n";
  1378.             }
  1379.         }
  1380.     }
  1381.     $_= $original;
  1382. }
  1383.  
  1384. #sub OBS_skip_print{
  1385. #    if($debug_flag == 1){
  1386. #        s/\s*$//;
  1387. #        print OUT '(---skip '.$_.'---)'."\n";
  1388. #    }
  1389. #}
  1390.  
  1391. sub OBS_skip_print{
  1392.     s/\s*$//;
  1393.     print OUT '(---skip '.$_.'---)'."\n";
  1394. }
  1395.  
  1396. sub shikaku_kakko_kensa{
  1397.     my ($line)= @_;
  1398.     my $kakko_suu= 0;
  1399.  
  1400.     while($line =~ /([\[\]])/g){
  1401.         if($1 eq '['){ $kakko_suu++; }
  1402.         else{
  1403.             $kakko_suu--;
  1404.             if($kakko_suu < 0){ last; }
  1405.         }
  1406.     }
  1407.     if($kakko_suu != 0){
  1408.         print OUT '(---èçî╩é¬ò┬é╢é─éóé▄é╣é±---)'."\n";
  1409.         close(OUT);
  1410.         exit;
  1411.     }
  1412. }
  1413.  
  1414. sub kakko_print{
  1415.     ($_)= @_;
  1416.     while(/\(.*?\)/){
  1417.         ($pre_line,$post_line)= ($`,$');
  1418.         print OUT $&;
  1419.         while($post_line =~ /\)/g){
  1420.             ($post_pre_line,$post_post_line)= ($`,$');
  1421.             if($post_pre_line !~ /\(/){
  1422.                 print OUT $post_pre_line.')';
  1423.                 $post_line= $post_post_line;
  1424.             }
  1425.         }
  1426.         print OUT "\n";
  1427.         $_= $pre_line.$post_line;
  1428.     }
  1429.     if($_ =~ /^\s*N?\d*\s*$/){ $_= ""; }
  1430.     return $_;
  1431. }
  1432.  
  1433. sub extra_print{
  1434.     ($line)= @_;
  1435.     my ($new_line,$char,$str,$num,@modal);
  1436.  
  1437.     $_= $line;
  1438.     while(/([A-MO-Z])(\-?)([0-9\.]+)/){
  1439.         $_= $';
  1440.         ($char,$str,$num)= ($1,$2,$3);
  1441.         $num= shutsuryoku_marume($char,$num);
  1442.         $new_line= $new_line.$char.$str.$num;
  1443.  
  1444.         if($char eq "G"){
  1445.             $value[4000 + $G_group{$num}]= $num;
  1446.             $value[4200 + $G_group{$num}]= $num;
  1447.             push(@modal,'(----#'.(4000+$G_group{$num}).'= '.$num.'----)'."\n");
  1448.         }
  1449.         elsif($char =~ /[BFHMST]/){
  1450.             $value[$system_value_modal{$char}]= $num;
  1451.             $value[$system_value_modal{$char}+200]= $num;
  1452.             push(@modal,'(----#'.$system_value_modal{$char}.'= '.$num.'----)'."\n");
  1453.         }
  1454.     }
  1455.     if(/\s+$/){ $new_line= $new_line."\n"; }
  1456.     print OUT $new_line;
  1457.     if($modal_flag == 1){
  1458.         foreach (@modal){ print OUT; }
  1459.     }
  1460.  
  1461.     kotei_cycle($line);
  1462.     
  1463.     if($G66_modal_tajuudo > 0){
  1464.         if($G66_yobidashi_tajuudo < $G66_modal_tajuudo){
  1465.             $_= $line;
  1466.             if(!/G92/ and $kotei_cycle == 0){
  1467.                 if(/X\-*[0-9\.]+/ or /Y\-*[0-9\.]+/ or /Z\-*[0-9\.]+/){
  1468.                     G66_modal_yobidashi($G66_modal_tajuudo - $G66_yobidashi_tajuudo);
  1469.                 }
  1470.             }
  1471.         }
  1472.     }
  1473. }
  1474.  
  1475. sub kotei_cycle{
  1476.     ($_) = @_;
  1477.     if(/G7[346]/ or /G8[1-9]/){ $kotei_cycle= 1; }
  1478.     elsif(/G80/ or /G0*[0123][A-Z\s]/ or /G33/){ $kotei_cycle= 0; }
  1479. }
  1480.  
  1481. sub naibu_marume{
  1482.     my ($num)= @_;
  1483.     my ($num1,$num2,$num3,$reverse_num,$num_length,$yuukou_num_length,$char,$i);
  1484.     my ($minus_flag,$seisuu_keta,$offset_shousuu_keta)= (0,0,0);
  1485.     my ($seisuu_bu,$shousuu_bu)= ("","");
  1486.  
  1487.     if(abs($num) < 1/(10**10)){ $num= 0; }
  1488.     $reverse_num= reverse($num);
  1489.     if($reverse_num =~ /\-$/){
  1490.         $minus_flag= 1;
  1491.         chop($reverse_num);
  1492.     }
  1493.     $char= chop($reverse_num);
  1494.     if($char ne "0"){
  1495.         $seisuu_bu= $char;
  1496.         $num_length= length($reverse_num);
  1497.         for($i=1;$i<=$num_length;$i++){
  1498.             $seisuu_keta++;
  1499.             $char= chop($reverse_num);
  1500.             if($char eq '.'){ last; }
  1501.             else{ $seisuu_bu= $seisuu_bu.$char; }
  1502.         }
  1503.     }
  1504.     else{ chop($reverse_num); }
  1505.     $shousuu_bu= reverse($reverse_num);
  1506.  
  1507.     if($seisuu_bu eq ""){
  1508.         $num_length= length($reverse_num);
  1509.         for($i=1;$i<=$num_length;$i++){
  1510.             $char= chop($reverse_num);
  1511.             if($char ne "0"){ last; }
  1512.             else{ $offset_shousuu_keta++; }
  1513.         }
  1514.     }
  1515.  
  1516.     $num1= $seisuu_bu.$shousuu_bu;
  1517.     $yuukou_num_length= length($num1);
  1518.     $yuukou_num_length -= $offset_shousuu_keta;
  1519.  
  1520.     if($yuukou_num_length > 8){
  1521.         $num2= substr($num1,0,8+$offset_shousuu_keta);
  1522.         $num3= '0.'.substr($num1,8+$offset_shousuu_keta,1);
  1523.         $num2= $num2 + round($num3);
  1524.  
  1525.         if($seisuu_keta > 8){
  1526.             $num= $num2;
  1527.             while($seisuu_keta > 8){
  1528.                 $num= $num.'0';
  1529.                 $seisuu_keta--;
  1530.             }
  1531.         }
  1532.         elsif($seisuu_keta != 0){
  1533.             if(length($num2) > 8){ $seisuu_keta++; }
  1534.             $num= substr($num2,0,$seisuu_keta).'.'.substr($num2,$seisuu_keta,8-$seisuu_keta);
  1535.         }
  1536.         else{
  1537.             $offset_shousuu_keta -= (length($num2) - 8);
  1538.             if($offset_shousuu_keta < 0){
  1539.                 $num= substr($num2,0,-$offset_shousuu_keta).'.'.substr($num2,-$offset_shousuu_keta,7);
  1540.             }
  1541.             else{ $num= '0.'.'0'x$offset_shousuu_keta.substr($num2,0,8+$offset_shousuu_keta); }
  1542.         }
  1543.         if($minus_flag == 1){ $num= '-'.$num; }
  1544.     }
  1545.     return $num;
  1546. }
  1547.  
  1548.  
  1549. sub shutsuryoku_marume{
  1550.     my ($char,$num)= @_;
  1551.     my $num1;
  1552.  
  1553.     if($num =~ /(0*)([0-9\.]+)/){
  1554.         ($num1,$num)= ($1,$2);
  1555.         if($num =~ /^\./){
  1556.             chop($num1);
  1557.             $num= '0'.$num;
  1558.         }
  1559.     }
  1560.  
  1561.     $num= $num * 1000;
  1562.     $num= round($num);
  1563.     $num= $num / 1000;
  1564.  
  1565.     if($num !~ /\./ and $num != 0){ $num= $num.'.'; }
  1566.  
  1567.     if($char =~ /[GMSTPDH]/ and $num =~ /.$/){ $num= round($num); }
  1568.     elsif($char eq 'F'){
  1569.         if($F_flag == 0 and $num =~ /\.0*$/){ $num = round($num); }
  1570.     }
  1571.     $num= $num1.$num;
  1572.     return $num;
  1573. }
  1574.  
  1575. sub round{
  1576.     my ($num)= @_;
  1577.     if($num >= 0){ $num= int($num + 0.5); }
  1578.     else{ $num= int($num - 0.5); }
  1579.     return $num;
  1580. }
  1581.  
  1582. sub fup{
  1583.     my ($num)= @_;
  1584.     my $num2;
  1585.     $num2= int($num);
  1586.      if($num != $num2){
  1587.         if($num > 0){ $num2++; }
  1588.         else{ $num2--; }
  1589.     }
  1590.     return $num2;
  1591. }
  1592.  
  1593. sub bcd_shori{
  1594.     my ($num)= @_;
  1595.     $num= hex($num);
  1596.     return $num;
  1597. }
  1598.  
  1599. sub bin_shori{
  1600.     my ($num)= @_;
  1601.     $num= sprintf("%x",$num);
  1602.     return $num;
  1603. }
  1604.  
  1605. sub ten_to_two{
  1606.     my ($num)= @_;
  1607.     $num= sprintf("%d",unpack("B32",pack("n",$num)));
  1608.     return $num;
  1609. }
  1610.  
  1611. sub two_to_ten{
  1612.     my ($num)= @_;
  1613.     $num= unpack("N",pack("B32",substr("0"x32 . $num,-32)));
  1614.     return $num;
  1615. }
  1616.  
  1617. sub and_shori{
  1618.     my ($num1,$num2)= @_;
  1619.     $num1= ten_to_two($num1);
  1620.     $num2= ten_to_two($num2);
  1621.  
  1622.     $num1= $num1 & $num2;
  1623.     $num1= two_to_ten($num1);
  1624.     return $num1;
  1625. }
  1626.  
  1627. sub or_shori{
  1628.     my ($num1,$num2)= @_;
  1629.     $num1= ten_to_two($num1);
  1630.     $num2= ten_to_two($num2);
  1631.  
  1632.     $num1= $num1 | $num2;
  1633.     $num1= two_to_ten($num1);
  1634.     return $num1;
  1635. }
  1636.  
  1637. sub xor_shori{
  1638.     my ($num1,$num2)= @_;
  1639.     $num1= ten_to_two($num1);
  1640.     $num2= ten_to_two($num2);
  1641.  
  1642.     $num1= $num1 ^ $num2;
  1643.     $num1= two_to_ten($num1);
  1644.     return $num1;
  1645. }
  1646.